<?php
/**
 * lsys task
 * @author     Lonely <shan.liu@msn.com>
 * @copyright  (c) 2017 Lonely <shan.liu@msn.com>
 * @license    http://www.apache.org/licenses/LICENSE-2.0
 */
if (!defined('LSYS_CRON_USER')){
	$web_user=array('nobody','www');
	foreach ($web_user as $u){
		$userinfo = posix_getpwnam($u);
		if(isset($userinfo['uid']))break;
	}
	foreach($argv as $u){
		if(isset($is_u)){
			$u=trim($u);break;
		}
		if($u=='-u')$is_u=true;
	}
	if (isset($u))define("LSYS_CRON_USER", $u);
}
if(defined('LSYS_CRON_USER')){
	$userinfo = posix_getpwnam(LSYS_CRON_USER);
	if(!isset($userinfo['uid'])) die("can't find user:".LSYS_CRON_USER);
	@posix_setuid($userinfo['uid']);
}
unset($u,$is_u,$userinfo,$web_user);